/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package group2assignone.model;

import group2assignone.dao.MyDAO;
import group2assignone.ucm.UCStartup;

/**
 *
 * @author Natalie
 */
public class DiscountedTicket extends Ticket
{
    private Ticket ticket;
    private Flight f;
    private boolean booked = false;;
    
    public DiscountedTicket(Ticket ticket)
    {
        this.ticket = ticket;
        getFlight();
    }
    
    public void getFlight()
    {
        MyDAO coms = UCStartup.getInstance().getDAO();
        f = coms.sQLGetFlight(ticket.getFlightNum());
    }
    
    @Override
    public double getCost()
    {
       double cost = 0;
       
       cost = Double.valueOf(f.getCost()) * f.getPromotion() / 100;

       return cost;
    }

    @Override
    public double getGST()
    {
        double gst = getCost() * GSTax.getInstanceGSTax().getGST() / 100;


        return gst;

    }

    @Override
    public double getAirportTax()
    {
        //Get departure location
        String depLoc = f.getDepLoc();
        MyDAO coms = UCStartup.getInstance().getDAO();
        double airportTax = coms.sQLGetAirportTax(f.getDepLoc());
        return airportTax;
    }

    @Override
    public int bookTicket(int bookingNum, int itemNum)
    {
        System.out.println("Discounted Ticket booked for:"+ticket.getUsername() + ". Flight: " + ticket.getFlightNum());
        MyDAO coms = UCStartup.getInstance().getDAO();
        booked = coms.sQLMakeBooking(ticket, bookingNum, itemNum);
        itemNum = itemNum + 1;
        return itemNum;
    }

    public boolean isBooked()
    {
        return booked;
    }
}
